import instance from './index';
import * as util from "@/assets/util";
//获取角色列表
const request = {
  p: ['get,/role'],
  r: params => {
    return instance.get(util.baseUrl+`/role/all`, {headers: {'token':util.session("token")}})
  },
  //根据名字获取列表
  requestByUsername: params => {
    return instance.get(util.baseUrl+`/role/selectRoleByName`, {params:{"roleName":params},headers: {'token':util.session("token")}})
  },
  getPermissionMenu: params => {
    return instance.get(util.baseUrl + `/permission/getPermissionMenu`,{headers: {'token':util.session("token")}});
  },
  getPermissionByMenuId: params => {
    return instance.get(util.baseUrl + `/permission/getPermissionByMenuId`,{params:{'menuId':params.menuId,'roleId':params.roleId},headers: {'token':util.session("token")}});
  }
};
//删除角色
const remove = {
  p: ['delete,/role/**'],
  r: params => {
    return instance.delete(util.baseUrl+`/role/delete`,{params:{"roleId":params},headers: {'token':util.session("token")}})
  },
  removeRole: params =>{
    return instance.delete(util.baseUrl+`/role/delete`,{params:{"roleId":params},headers: {'token':util.session("token")}})
  }
};
//角色添加权限
const add = {
  addPermission: params => {
    return instance.post(util.baseUrl + '/rolePermission/roleAddPermission',params,{headers:{'token':util.session("token")}})
  },
  addRole: params=> {
    return instance.post(util.baseUrl + `/role/save`,params,{headers:{'token':util.session("token")}})
  }
};
//越权请求
const notAllowed = {
  p: ['get,/roles/notAllowed'],
  r: params => {
    return instance.get(util.baseUrl+`/roles/notAllowed`, {params})
  }
}

export {
  request,
  remove,
  add,
  notAllowed
}
